package SceneTrigger

import (
	"misc/Clojure"
	. "misc/Clojure/parse"
	"time"
)

/////WaitAction//////////////////
type WaitAction struct {
	TriggerActionInfo
	isFinish bool
	WaitTime float64
	endTime  time.Time
}

func NewWaitAction(args []Node) IBlockTrigerAction {
	retAction := &WaitAction{}
	retAction.isFinish = false
	waitNumber := args[1].(*NumberNode).Val.(float64)
	retAction.WaitTime = waitNumber
	return retAction
}
func (w *WaitAction) OnExec(context *Clojure.Context) {
	w.isFinish = false
	w.endTime = time.Now().Add(time.Millisecond * time.Duration(w.WaitTime*1000))
}

func (w *WaitAction) GetActionInfo() *TriggerActionInfo {
	return &w.TriggerActionInfo
}

func (w *WaitAction) IsFinish() bool {
	return w.isFinish
}

func (w *WaitAction) Update() {
	if time.Now().UnixNano() > w.endTime.UnixNano() {
		w.isFinish = true
	}
}

func (w *WaitAction) OnExit() {

}
